/*****************************************************
PROJECT: BRIDGE C2 SCRAP
JOB:
REQUESTOR:Rachel Gold
JIRA #:
ANALYST: MLT
DATE: 9/15/2022
   rerun 12/14/2023 on deduplicated denominator;
VERSION: 
LAST UPDATED: 
PEER REVIEWER: 

PROJECT DESCRIPTION: Use ASCEND approach to compare CRC, BC and 
BC cancer prevention services in patients with
	No SDH Screening
	Documented Need
	Documented No Need
Stratified by SDH need: Food, Housing, Transportation
STUDY PERIOD: 7/1/2016-2/29/2020		

DETAILS (this file): 
Table 1 for BC
    Patients
	Race and ethnicity
	Preferred language
	Age at Index encounter (median, range)
	Age Group at Index
	Payer at Index
	FPL 
	Visit per Year
	Years of Observation
	BC status at Index
	Last BC screen type prior to Index
	Years of Observation after first Due date
	Ever due for screening during observation	
Columns Food Insecurity: Need/ No Need/ Not documented
Columns Housing Insecurity: Need/ No Need/ Not documented
Columns Transportation Insecurity: Need/ No Need/ Not documented
		

INPUT DATA:
SCRAP.BC_patient_covariates;
SCRAP.BC_status_at_index;

OUTPUT DATA:


RELATED FILE: 


SECTIONS:

****************************************************/
options compress=yes reuse=yes;
libname SCRAP "e:\\sasroot\BRIDGE C2\SCRAP\";
libname final "e:\\sasroot\BRIDGE C2\SCRAP\BC_table_1";
libname RD odbc noprompt="dsn=research_dev;Trusted_Connection=yes" bulkload=yes;
/****************************************************/


data analysis0;
set SCRAP.BC_patient_covariates;
rename sdh_transportation=sdh_trans;
run;
proc sort data=analysis0 out=analysis;
by advance_patid;
run;
data single multiple;
set analysis;
by advance_patid;
if first.advance_patid and last.advance_patid then output single;
if ^(first.advance_patid and last.advance_patid) then output multiple;
run;

proc sort nodup data=multiple out=multiple2 dupout=dups;
by advance_patid;
run;

data single2 mult3;
set multiple2;
by advance_patid;
if first.advance_patid and last.advance_patid then output single2;
if ^(first.advance_patid and last.advance_patid) then output mult3;
run;
data analysis;
set single single2;
run;
data status_index;
set SCRAP.bc_status_at_index;
rename sdh_transportation=sdh_trans;
run;
proc sql;
select count(advance_patid), count(distinct advance_patid) from analysis;
run;

/*Headers setting dynamic variables*/
%let cancer=BC;

/*************************************************
STEP 1: 
Uncomment lines 119-121
Run full progarm to generate food_insecurity numbers
**************************************************/
%let sdh=SDH_food;

%let sdh=SDH_housing;

%let sdh=SDH_trans;

proc freq data=analysis;
tables sex_r*&sdh/norow ;
run;

proc freq data=analysis;
tables race_ethnic*&sdh/norow nopercent nofreq;
run;

/*	Preferred language*/

proc freq data=analysis;
tables english*&sdh/norow nopercent nofreq;
run;



/*	Age Group at Index*/

proc freq data=analysis;
tables age_cat*&sdh/norow nopercent nofreq;
run;



/*	Payer at Index*/

proc freq data=analysis;
tables payor_type_research*&sdh/norow nopercent nofreq;
run;



/*	FPL */

proc freq data=analysis;
tables FPL_cat*&sdh/norow nopercent nofreq; ;
run;


/*	Visit per Year*/


proc freq data=analysis;
tables visit_cat*&sdh/norow nopercent nofreq;
run;


run;


/*	Years of Observation*/

proc freq data=analysis;
tables obs_cat*&sdh/norow nopercent nofreq;
run;



/*	BC status at Index*/
proc freq data=status_index;
tables status_at_index*&sdh/norow nopercent nofreq;
run;



/*	Ever due for screening during observation	*/
proc freq data=status_index;
tables ever_due*&sdh/norow nopercent nofreq;;
run;



/*/N for categories*/
proc freq data=analysis;
tables race_ethnic english age_cat
payor_type_research FPL_cat visit_cat
obs_cat/ ;
run;



proc freq data=status_index;
tables status_at_index ever_due;
run;



proc freq data=status_index;
tables status_at_index ever_due/norow nocol nopercent;
run;

proc freq data=analysis;
tables sdh_food SDH_housing SDH_trans;
run;